package com.hzz.framework.config;

import com.hzz.framework.filter.CrossFilter;
import com.hzz.framework.filter.ExceptionAndExecuteTimeFilter;
import com.hzz.framework.filter.JwtFilter;
import com.hzz.framework.filter.RewriteFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FilterConfig {
    @Bean
    public JwtFilter jwtFilter() {
        return new JwtFilter();
    }

    @Bean
    public CrossFilter crossFilter() {
        return new CrossFilter();
    }

    @Bean
    public ExceptionAndExecuteTimeFilter exceptionAndExecuteTimeFilter() {
        return new ExceptionAndExecuteTimeFilter();
    }

    @Bean
    public FilterRegistrationBean testFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new RewriteFilter());//注册rewrite过滤器
        registration.addUrlPatterns("/*");
        registration.addInitParameter("paramName", "paramValue");
        registration.addInitParameter(RewriteFilter.REWRITE_TO, "/index.html");
        registration.addInitParameter(RewriteFilter.REWRITE_PATTERNS, "/v/*");
        registration.setName("rewriteFilter");
        registration.setOrder(1);
        return registration;
    }
}
